package com.xuning.emperor.business.impl;

import com.xuning.emperor.base.BusinessImpl;
import com.xuning.emperor.business.IUserBusiness;
import com.xuning.emperor.converter.UserConverter;
import com.xuning.emperor.domain.dto.UserDTO;
import com.xuning.emperor.domain.po.User;
import com.xuning.emperor.domain.vo.UserVO;
import com.xuning.emperor.service.IUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * @author wangqx
 * @description 用户业务层
 * @date 2022/6/16
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class UserBusinessImpl extends BusinessImpl<IUserService, UserConverter, UserVO, UserDTO, User> implements IUserBusiness {


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(UserDTO dto) {
        User user=converter.toPO( dto);
        service.save(user);
        return true;
    }

    @Override
    public List<UserVO> list(UserDTO d) {
        List<User> userList=service.list();
        return converter.toVO(userList);
    }

    @Override
    public IPage<UserVO> page(IPage<UserVO> page, UserDTO d) {

        Page<User> poPage=new Page<User>();
        poPage.setSize(page.getSize());
        poPage.setCurrent(page.getCurrent());
        Page<User> userPage=service.page(poPage,new QueryWrapper<User>());
        return converter.toVO(userPage);
    }

    @Override
    public UserVO get(Serializable id) {
        return null;
    }

    @Override
    public boolean delete(Serializable id) {
        return false;
    }
}
